#include <Rectangle.h>

Rectangle::Rectangle(const double width, const double length):mWidth(width),mLength(length) 
{   
 
}

double Rectangle::getArea() const
{
      if((isValid (mWidth)) && (isValid (mLength)))
	return formatOutput(mWidth*mLength);
      else
        return 0;
}

double Rectangle::getPrimeter() const
{
       if((isValid (mWidth)) && (isValid (mLength)))
	 return (2 * (mWidth + mLength));
       else
         return 0;
}

void Rectangle::setLength(const double value)
{
  double formatedValue = formatInput(value);
  if (isValid(formatedValue))
    mLength = formatedValue;
}

void Rectangle::setWidth(const double value)
{
  double formatedValue = formatInput(value);
  if (isValid(formatedValue))
    mWidth = formatedValue;
}

double Rectangle::formatInput (const double side) const 
{
  int formatedValue = (int)(side * 100);
  return (double)formatedValue/100; 
}

double Rectangle::formatOutput (double result) const
{
  double tempValue = result + 0.005;
  return formatInput(tempValue);
} 

bool  Rectangle::isValid(const double side) const
{
   return ((side>0.00) && (side<=100.00));
}

